package com.adrian.misc.fractal.color;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.ImageObserver;

 public abstract class ColorMap {
	Color baseCol = null;
	int resolution = 0;	
	String colorMapNam = "";
	
	public  ColorMap (String name){
		colorMapNam = name;
	}
	public Color getBaseColor() {
		return baseCol;
	}
	/**
	private double func(double normVal) {
		return Math.sin(2*Math.pow(normVal-1.1,4));
	}*/
	
	public void demo(Image im, ImageObserver io) {
		Graphics g = im.getGraphics();
		int height = im.getHeight(io);
		int width = im.getWidth(io);
		double incr = 1.0/(double)width;
		System.out.println("####Demoing color..");
		for (int i=0;i<width;i++) {
			g.setColor(getColor(i*incr));
			g.drawLine(i, 0, i, height);
		}
		g.setColor(baseCol.darker().darker());
		g.setFont(new Font("Verdana",Font.BOLD,(height/5)));
		String sMap = this.getClass().getSimpleName();
		g.drawString(colorMapNam, (int)(.05*width),(height-g.getFont().getSize())/2);
		g.setFont(new Font("Verdana",Font.PLAIN+Font.ITALIC,(height/5)));
		g.drawString("("+sMap.substring(0,sMap.indexOf("ColorMap"))+")", (int)(.05*width),(height + g.getFont().getSize())/2);
		
		float[] hsb = new float[3];
		hsb = Color.RGBtoHSB(baseCol.getRed(), baseCol.getGreen(), baseCol.getBlue(), hsb);
		g.setColor(Color.getHSBColor(hsb[0], hsb[1], ((hsb[2]+ 0.3f)/1.3f)).brighter().brighter());
		g.setFont(new Font("Verdana",Font.BOLD,(height/5)));
		sMap = this.getClass().getSimpleName();
		g.drawString(colorMapNam, (int)(.05*width)-1,(height-g.getFont().getSize())/2 -1);
		g.setFont(new Font("Verdana",Font.PLAIN+Font.ITALIC,(height/5)));
		g.drawString("("+sMap.substring(0,sMap.indexOf("ColorMap"))+")", (int)(.05*width)-1,(height + g.getFont().getSize())/2 -1 );

	}
	public int getResolution() {
		return resolution;
	}
	public abstract Color getColor(double val);

	@Override
	public String toString() {
		return colorMapNam;
	}
}
 
